static CIPHER: [char; 26] = ['z', 'y', 'x', 'w', 'v', 'u', 't', 's', 'r', 'q', 'p', 'o', 'n', 'm', 'l', 'k', 'j', 'i', 'h', 'g', 'f', 'e', 'd', 'c', 'b', 'a'];

/// "Encipher" with the Atbash cipher.
pub fn encode(plain: &str) -> String {
    plain
        .to_ascii_lowercase()
        .replace(" ", "")
        .replace(",", "")
        .replace(".", "")
        .chars()
        .collect::<Vec<char>>()
        .chunks(5)
        .into_iter()
        .fold(String::new(), |mut acc, v| {
            let mut tmp = v
                .iter()
                .map(|&ch| if ch.is_ascii_alphabetic() { CIPHER[ch as usize - 97] } else { ch })
                .collect::<String>();
            if acc.is_empty() {
                acc.push_str(tmp.as_str())
            } else {
                tmp.insert(0, ' ');
                acc.push_str(tmp.as_str());
            }
            acc
        })
}

/// "Decipher" with the Atbash cipher.
pub fn decode(cipher: &str) -> String {
    cipher
        .replace(" ", "")
        .chars()
        .collect::<Vec<char>>()
        .chunks(5)
        .into_iter()
        .fold(String::new(), |mut acc, v| {
            let mut tmp = v
                .iter()
                .map(|&ch| if ch.is_ascii_alphabetic() {
                    CIPHER[(ch as u8 - 97) as usize]
                } else { ch }).collect::<String>();
                acc.push_str(tmp.as_str());
            acc
        })
}

#[test]
#[ignore]
fn encode_deep_thought() {
    assert_eq!(encode("Truth is fiction."), "gifgs rhurx grlm");
}